package com.moon.commonlib.util;

import android.util.Log;

import com.moon.commonlib.BuildConfig;

/**
 * Author: XuChang
 * Date: 2019/8/2 9:26
 * Description:
 * History:
 */
public class LogUtil {
    static final String TAG = "WebAppLog";
    final static boolean GLOBAL_SWITCH = BuildConfig.DEBUG; //全局的开关
//    final static boolean GLOBAL_SWITCH = true; //全局的开关
    final static LEVEL OUTPUT_LEVEL = LEVEL.ERROR;   //必须小于等于这个级别才输出



    enum LEVEL {

        ERROR(5),
        WARN(4),
        INFO(3),
        DEBUG(2);

        int level;

        LEVEL(int i) {
            this.level = i;
        }

        public int getLevel() {
            return level;
        }

        public boolean compare(LEVEL level) {
            return this.level <= level.level;
        }
    }


    public static void e(String msg) {
        e(TAG,msg);
    }

    public static void w(String msg) {
        if (!GLOBAL_SWITCH || !LEVEL.WARN.compare(OUTPUT_LEVEL))
            return;
        Log.e(TAG, msg);
    }

    public static void i(String msg) {
        if (!GLOBAL_SWITCH || !LEVEL.INFO.compare(OUTPUT_LEVEL))
            return;
        Log.e(TAG, msg);
    }

    public static void d(String msg) {
        if (!GLOBAL_SWITCH || !LEVEL.DEBUG.compare(OUTPUT_LEVEL))
            return;
        Log.e(TAG, msg);
    }

    public static void d(String tag,String msg) {
        if (!GLOBAL_SWITCH || !LEVEL.DEBUG.compare(OUTPUT_LEVEL))
            return;
        Log.e(tag, msg);
    }

    public static void e(String tag, String msg) {
        if (!GLOBAL_SWITCH || !LEVEL.ERROR.compare(OUTPUT_LEVEL))
            return;
        Log.e(tag, msg);
    }

}
